package com.ddwl.common.util;

import com.github.wujun234.uid.impl.CachedUidGenerator;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author hemiaojun
 * @Date 2020/12/31 16:21
 */
@Component
public class SnowflakeIdGenerator {

    @Resource
    private CachedUidGenerator cachedUidGenerator;

    /**
     * 获取uid
     * @return
     */
    public long nextId() {
        return cachedUidGenerator.getUID();
    }

    public String nextIdToString() {
        return String.valueOf(nextId());
    }

    public long getWorkId(){
        return cachedUidGenerator.getWorkerId();
    }

    /**
     * 格式化传入的uid，方便查看其实际含义
     * @param uid
     * @return
     */
    public String parse(long uid) {
        return cachedUidGenerator.parseUID(uid);
    }

}
